<?php
declare (strict_types=1);

namespace app\listener\agent;

use app\event\OldAgent;
use app\model\Agent;
use app\model\PageSetting;

class Coupon
{
    /**
     * 事件监听处理
     * @param OldAgent $event
     * @return mixed
     */
    public function handle(OldAgent $event)
    {
        /**
         * @var Agent
         */
        $agent = $event->agent;
        $pageSetting = new PageSetting();
        $baseParams = [
            'setting_name'  =>  '',
            'image'         =>  '',
            'type'          =>   PageSetting::TYPE_COUPON,
            'sub_category'  =>   '',
            'position'      =>   '',
            'jump_type'     =>   '0',
            'path'          =>   '',
            'agent_id'      =>  $agent->id,
            'source'        =>  PageSetting::SOURCE_ZDY,
        ];

        $head = $middle = $duff = $varray = $baseParams;

        //1.初始化头部轮播图
        $head['setting_name'] = '话费充值享优惠';
        $head['image']        = env('app.api_url').'/static/images/home/headSlider.png';
        $head['sub_category'] = PageSetting::SUB_CATEGORY_SYLBT;
        $head['position']     = PageSetting::POSITION_HEAD;
        $pageSetting->doSave($head);
        unset($head);

        //2.初始化中间轮播图
        $middle['setting_name'] = '饿了么会员';
        $middle['image']        = env('app.api_url').'/static/images/home/elm.png';
        $middle['sub_category'] = PageSetting::SUB_CATEGORY_SYLBT;
        $middle['position']     = PageSetting::POSITION_MIDDLE;
        $middle['jump_type']    = '1';
        $middle['path']         = '/quanyi/detail?brandId=7';
        $pageSetting->doSave($middle);
        unset($middle);

        //3.初始化豆腐块
        $ad_blocks = [
            [
                'name'      => '电影',
                'image_url' => env('app.api_url').'/static/images/home/icon_tofu_movie.png',
                'path'      => '/movie/index',
                'jump_type' => '4',
                'sort'      => '3',
            ],
            [
                'name'      => 'QQ音乐',
                'image_url' => env('app.api_url').'/static/images/home/icon_qq_tofu_music.png',
                'brand_id'  => '20',
                'jump_type' => '5',
                'path'      => '/quanyi/detail?brandId=20',
                'sort'      => '4',
            ],
            [
                'name'      => '饿了么',
                'image_url' => env('app.api_url').'/static/images/home/icon_tofu_elm.png',
                'brand_id'  => '7',
                'jump_type' => '5',
                'path'      => '/quanyi/detail?brandId=7',
                'sort'      => '1',
            ],
            [
                'name'      => '美团',
                'image_url' => env('app.api_url').'/static/images/home/icon_tofu_meituan.png',
                'brand_id'  => '6',
                'jump_type' => '5',
                'path'      => '/quanyi/detail?brandId=6',
                'sort'      => '2',
            ]
        ];
        $duff['sub_category'] = PageSetting::SUB_CATEGORY_DFK;
        foreach ($ad_blocks as $ad_block) {
            $duff['setting_name'] = $ad_block['name'];
            $duff['image']        = $ad_block['image_url'];
            $duff['jump_type']    = $ad_block['jump_type'];
            $duff['path']         = $ad_block['path'];
            $pageSetting->doSave($duff);
        }
        unset($duff);

        //4.初始化金刚区
        $varray_blocks = [
            [
                'name'      => '腾讯',
                'image_url' => env('app.api_url').'/static/images/home/icon_qqv.png',
                'brand_id'  => '2',
                'id'        => '2',
                'jump_type' => '5',
                'path'      => '/quanyi/detail?brandId=2',
            ],
            [
                'name'      => '优酷',
                'image_url' => env('app.api_url').'/static/images/home/icon_youku.png',
                'brand_id'  => '3',
                'id'        => '3',
                'jump_type' => '5',
                'path'      => '/quanyi/detail?brandId=3',
            ],
            [
                'name'      => '爱奇艺',
                'image_url' => env('app.api_url').'/static/images/home/icon_iqiyi.png',
                'brand_id'  => '1',
                'id'        => '1',
                'jump_type' => '5',
                'path'      => '/quanyi/detail?brandId=1',
            ],
            [
                'name'      => '喜马拉雅',
                'image_url' => env('app.api_url').'/static/images/home/icon_ximalaya.png',
                'brand_id'  => '5',
                'id'        => '5',
                'jump_type' => '5',
                'path'      => '/quanyi/detail?brandId=5',
            ],
            [
                'name'      => 'QQ音乐',
                'image_url' => env('app.api_url').'/static/images/home/icon_qqyinyue.png',
                'brand_id'  => '20',
                'id'        => '20',
                'jump_type' => '5',
                'path'      => '/quanyi/detail?brandId=20',
            ]
        ];
        $varray['sub_category'] = PageSetting::SUB_CATEGORY_SYJGQ;
        foreach ($varray_blocks as $vajra_block) {
            $varray['setting_name'] = $vajra_block['name'];
            $varray['image']        = $vajra_block['image_url'];
            $varray['jump_type']    = $vajra_block['jump_type'];
            $varray['path']         = $vajra_block['path'];
            $pageSetting->doSave($varray);
        }
        unset($varray);
    }
}
